package com.novellotus.iov.carvice.activity;

import android.os.Bundle;
import android.widget.EditText;

import com.novellotus.httploadingview.LoadingView;
import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.adapter.CarListAdapter;
import com.novellotus.iov.carvice.adapter.TaskAdapter;
import com.novellotus.iov.carvice.bean.RxTaskListBean;
import com.novellotus.iov.carvice.model.SearchTaskModel;
import com.novellotus.iov.carvice.utils.MyUtils;
import com.novellotus.iov.carvice.utils.MyViewUtils;
import com.novellotus.iov.carvice.view.PageView;
import com.orangegangsters.github.swipyrefreshlayout.library.RefreshLayout;
import com.orangegangsters.github.swipyrefreshlayout.library.RefreshLayoutDirection;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 搜索售后
 * */
public class SearchTaskActivity extends BaseActivity implements TaskAdapter.ItemClickInterface, CarListAdapter.ClickItemInterface, RefreshLayout.OnRefreshListener, LoadingView.OnBtnClickListener, PageView.PageViewInterface, SearchTaskModel.SearchInterface {

    @BindView(R.id.pageView)
    PageView pageView;
    @BindView(R.id.edt_search)
    EditText edt_search;
    TaskAdapter taskAdapter;
    SearchTaskModel searchTaskModel;

    @Override
    protected void initContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_sear_task);
    }

    @Override
    public void init() {
        searchTaskModel = new SearchTaskModel(this, this);
        taskAdapter = new TaskAdapter(this, null);
        searchTaskModel.setSearchEditText(edt_search);
        pageView.refreshLayout.setOnRefreshListener(this);
        pageView.setBottomInterface(taskAdapter);
        pageView.setReLoadBtnListener(this);
        pageView.setPageViewInterface(this);
        pageView.setRecyclerViewAdapter(MyViewUtils.getLinearLayoutManager(this), taskAdapter);
    }


    @OnClick(R.id.tv_cancel)
    void back() {
        MyUtils.hideInput(this);
        finish();
    }

    @Override
    public void openDetail(String plate, String vin, int type) {

    }

    @Override
    public void loadData(int dataPage) {
        searchTaskModel.getList(edt_search, pageView, taskAdapter);
    }

    @Override
    public void onReload() {
        searchTaskModel.getList(edt_search, pageView, taskAdapter);
    }

    @Override
    public void onRefresh(RefreshLayoutDirection direction) {
        pageView.refreshData(direction);
    }

    @Override
    public void searchTask() {
        searchTaskModel.getList(edt_search, pageView, taskAdapter);
    }

    @Override
    public void clickItem(RxTaskListBean.RecordsBean record) {
        Bundle bundle = new Bundle();
        bundle.putString("fid", record.getId());
        bundle.putString("plate", record.getPn());
        bundle.putString("vin", record.getVin());
        bundle.putString("statue", record.getStatus());
        openActivity(TaskDetailActivity.class, bundle);
    }
}
